package com.seckill.item.controller;


import com.baomidou.mybatisplus.extension.service.IService;
import com.seckill.api.dto.item.ItemSearchDTO;
import com.seckill.api.dto.item.ItemSimpleInfoDTO;
import com.seckill.item.domian.dto.ItemDTO;
import com.seckill.item.domian.dto.OrderDetailDTO;
import com.seckill.item.service.IItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zsc
 * @since 2025-05-17
 */
@Api(tags = "商品相关接口")
@RestController
@RequestMapping("/item")
@Slf4j
@Validated
public class ItemController {
    @Autowired
    private IItemService itemService;

    //新增商品
    @ApiOperation("新增商品")
    @PostMapping("/add")
    public void add(@RequestBody ItemDTO itemDTO) {
        itemService.add(itemDTO);
    }

    //修改商品
    @ApiOperation("修改商品")
    @PutMapping("/update")
    public void update(@RequestBody ItemDTO itemDTO) {
        itemService.update(itemDTO);
    }

    //删除商品
    @ApiOperation("删除商品")
    @DeleteMapping("/delete/{id}")
    public void delete(@RequestParam("id") Long id) {
        itemService.delete(id);
    }

    //下架商品
    @ApiOperation("下架商品")
    @PutMapping("/downShelf/{id}")
    public void downShelf(@RequestParam("id") Long id){
        itemService.downShelf(id);
    }

    //上架商品
    @ApiOperation("上架商品")
    @PutMapping("/upShelf/{id}")
    public void upShelf(@RequestParam("id") Long id) {
        itemService.upShelf(id);
    }

    //扣减库存
    @ApiOperation("扣减库存")
    @PutMapping("/deductStock")
    public void deductStock(@RequestBody OrderDetailDTO orderDetailDTO) {
        itemService.deductStock(orderDetailDTO);
    }

    @ApiOperation("获取商品搜索信息")
    @GetMapping("/{id}/searchInfo")
    ItemSearchDTO getSearchInfo(@PathVariable("id") Long id){
        return itemService.getSearchInfo(id);
    }

    @ApiOperation("获取商品简单信息")
    @GetMapping("/simpleInfo/list")
    List<ItemSimpleInfoDTO> getSimpleInfoList(@RequestParam("ids") List<Long> ids){
        return itemService.getSimpleInfoList(ids);
    }

}
